<template>
  <a-modal
    :title="title"
    :visible="visible"
    :maskClosable="false"
    :width="1000"
    @cancel="handleCancel">
    <template>
      需要根据后台返回的数据渲染弹出框样式
    </template>
  </a-modal>
</template>

<script>
import { DATA_CODE_SUCCESS } from '@/utils/consts';
import { request, METHOD } from '@/utils/request';
const API_BASE_URL = require('@/services/baseUrl')

export default {
  name: 'customModal',
  data() {
    return {
      title: 'default',
      visible: false,
      oriData: {},
      columns: [],
      dataSource: [],
      selectedRowKeys: [],
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showSizeChanger: true,
        showTotal: (val) => `共 ${val} 条记录 第 ${this.pagination.current} / ${Math.ceil(this.pagination.total / this.pagination.pageSize)} 页`
      }
    };
  },
  methods: {
    show(columns, oriData) {
      this.columns = columns;
      this.oriData = oriData;
      this.visible = true;
      this.selectedRowKeys = [];
      this.getList();
    },
    handleOk() {
      this.visible = false;
      this.$emit('selectData', this.dataSource[this.selectedRowKeys[0]], this.oriData.option, this.oriData.item, this.oriData.key);
    },
    handleCancel() {
      this.visible = false;
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys;
    },
    handleTableChange(pagination) {
      this.selectedRowKeys = [];
      Object.assign(this.pagination, pagination);
      this.getList();
    },
    async getList() {
      const params = { ...this.pagination };
      params.pageNum = params.current;
      const response = await request(API_BASE_URL + this.oriData.item.dataUrl, METHOD.GET, params);
      if (response.data.code === DATA_CODE_SUCCESS) {
        this.dataSource = response.data.data.content;
        this.pagination.total = response.data.data.totalElements;
      }
    }
  }
};
</script>
